package designPattern.prototype;

import java.lang.reflect.Field;

public class BeanUtils {
    public static Object copy(Object prototypeObj) {
        Class clazz = prototypeObj.getClass();
        Object returnObj = null;
        try {
            returnObj = clazz.newInstance();
            Field[] fields = clazz.getDeclaredFields();
            for(Field field : fields) {
                field.setAccessible(true);
                field.set(returnObj, field.get(prototypeObj));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return returnObj;
    }
}
